package com.my.all.mapper;

import com.my.all.pojo.Goods;
import org.apache.ibatis.annotations.*;

import java.util.List;

//将Mapper注解标记的类自动注册到SpringIoc容器中，由spring管理该类对象的生存周期
@Mapper
public interface GoodsMapper {
    /**
     * 新增一条商品信息
     * @param goods
     * @return
     */
    @Insert({"insert into goods(goodsName, goodsCount, goodsPrice, goodsInfo) " +
            "values (#{goodsName},#{goodsCount},#{goodsPrice},#{goodsInfo})"})
    int insertGoods(Goods goods);

    /**
     * 根据商品id删除商品信息
     * @param goodsId
     * @return
     */
    @Delete({"delete from goods where goodsId = #{goodsId}"})
    int deleteGoodsById(Long goodsId);

    /**
     * 查询全部商品信息
     * @return
     */
    @Select({"select * from goods"})
    List<Goods> selectAll();

    /**
     * 根据商品id查询商品信息
     * @param goodsId
     * @return
     */
    @Select({"select * from goods where goodsId=#{goodsId}"})
    Goods selectGoodsById(Long goodsId);

    /**
     * 根据商品id更新商品信息
     * @param goods
     * @return
     */
    @Update({"update goods set goodsCount=#{goodsCount}, goodsPrice=#{goodsPrice}" +
            ", goodsInfo=#{goodsInfo} where goodsId=#{goodsId}"})
    int updateGoods(Goods goods);
}
